home *** CD-ROM | disk | FTP | other *** search
- #define USE_MAIL_ADDRESSES 1
- /* Main.c */
- /*
- * AddressOMatic Sample
- * Main.c
- * Copyright © 1993 Apple Computer Inc. All rights reserved.
- */
- #define EXTERN /* */
- #ifndef USE_MAIL_ADDRESSES
- #define USE_MAIL_ADDRESSES 1
- #endif
- #include "AddressOMaticTest.h"
- #include <OCETemplates.h>
- #include <Palettes.h>
-
- #ifndef topLeft
- #define topLeft(r) (((Point *) &(r))[0])
- #define botRight(r) (((Point *) &(r))[1])
- #endif
- #define AOMPtr(window) ((AddressOMaticPtr) GetWRefCon(window))
-
- typedef struct EventString {
- AOMPanelState stateBit;
- StringPtr message;
- } EventString, *EventStringPtr;
-
- /*
- * kAOMFindInProgressMask is set while finding is ongoing. To prevent
- * flooding the error log, we only display changes. See DisplayEventString.
- */
- const EventString gEventString[] = {
- { kAOMPanelBecomesTargetMask, "\pPanel becomes target" },
- { kAOMAppBecomesTargetMask, "\pApplication becomes target" },
- /* { kAOMFindInProgressMask, "\pFind in progress" }, */
- { kAOMSelectedAnItemMask, "\pSelected an item" },
- { kAOMChangedSelectionMask, "\pChanged selection" },
- { kAOMDoneButtonHitMask, "\pDone button hit" },
- { kAOMCCButtonHitMask, "\pCC Button hit" },
- { kAOMBCCButtonHitMask, "\pBCC Button hit" },
- { kAOMToButtonHitMask, "\pTo Button hit" },
- { kAOMSaveButtonHitMask, "\pSave Button hit" },
- { 0, NULL }
- };
- void DisplayEventString(
- register BrowserPtr browserPtr
- );
-
- void DumpAuxColorRecord(
- register BrowserPtr browserPtr
- );
- void DumpColor(
- RGBColor *theColor,
- StringPtr result
- );
-
- /*
- * gTypeList contains a list of record types that we can search
- * for. It is initialized to "things we can send mail to."
- */
- #define kMaxPathParts 64
- RString *gTypeList[kMaxPathParts];
- short gTypeCount;
-
-
- /*
- * These enum's define items in the various menus.
- */
- enum AppleMenu {
- kAppleAbout = 1
- };
- enum FileMenu {
- kFileCreateWindow = 1,
- kFileCloseWindow,
- kFileUnused1,
- kFileSetIdentity,
- kFileUnused2,
- kFileQuit
- };
- enum EditMenu {
- kEditUndo = 1,
- kEditUnused,
- kEditCut,
- kEditCopy,
- kEditPaste,
- kEditClear
- };
-
- Boolean gInForeground;
- short gWindowOffset = 0;
-
- /*
- * Local function prototypes.
- */
- void main(void);
- void EventLoop(void);
- void ApplicationEventLoop(void);
- void DoMouseEvent(void);
- void ProcessActivateEvent(
- WindowPtr activeWindow,
- Boolean isActivate
- );
- void DoCommand(
- BrowserPtr browserPtr,
- long menuChoice
- );
- void AdjustMenus(void);
- void DeleteAllWindows(void);
- void InitMacintosh(void);
- void InitApplication(void);
- void AdjustEditMenu(
- Boolean isDeskAcc
- );
- void SetupTypesList(void);
- void MakeAddressOMaticWindow(void);
- void DisposeAddressOMatic(
- BrowserPtr browserPtr
- );
- void DoContentClick(
- BrowserPtr browserPtr
- );
- void DoWindowKeyDown(
- BrowserPtr browserPtr
- );
- Boolean DoPanelEvent(
- BrowserPtr browserPtr
- );
- void UpdateDestination(
- BrowserPtr browserPtr
- );
- void ProcessAOMSelection(
- register BrowserPtr browserPtr
- );
- void DisplayRecipients(
- register BrowserPtr browserPtr
- );
- void DisplayOneDSSpec(
- register BrowserPtr browserPtr,
- PackedDSSpecPtr theDSSpecPtr
- );
- /*
- * This is copied from the Snippits library.
- */
- OSErr GetUserIdentity(
- AuthIdentity *userIdentity
- );
- void CheckForAOCEToolbox(void);
-
- /*
- * main
- * The application main program.
- */
- void
- main()
- {
- InitMacintosh();
- InitApplication();
- CheckForAOCEToolbox();
- if (gHasAOCEToolbox == FALSE) {
- ErrorAlert(ALRT_Fatal, kOCEToolboxNotOpen, "\pAOCE Toolbox required");
- ExitToShell();
- }
- gInForeground = TRUE;
- SetupTypesList();
- MakeAddressOMaticWindow();
- InitCursor();
- gUpdateMenusNeeded = TRUE;
- while (gQuitNow == FALSE)
- EventLoop();
- ExitToShell();
- }
-
- /*
- * Application event loop: process one event each time.
- */
- void
- EventLoop(void)
- {
- register BrowserPtr browserPtr;
- long menuChoice;
- register WindowPtr theWindow;
- GrafPtr savePort;
- Boolean isActivating;
- Boolean mustHandleEvent;
- long sleepTime;
-
- if (gUpdateMenusNeeded)
- AdjustMenus();
- if (gFindInProgress)
- sleepTime = 0;
- else if (gInForeground)
- sleepTime = 10;
- else {
- sleepTime = 60;
- }
- WaitNextEvent(everyEvent, &EVENT, sleepTime, NULL);
- theWindow = FrontWindow();
- if (theWindow != NULL)
- SetPort(theWindow);
- if ((browserPtr = IsOurWindow(theWindow)) == NULL)
- mustHandleEvent = TRUE;
- else {
- mustHandleEvent = DoPanelEvent(browserPtr);
- }
- if (mustHandleEvent) {
- switch (EVENT.what) {
- case nullEvent:
- break;
- case keyDown:
- case autoKey:
- if ((EVENT.message & charCodeMask) == '.'
- && (EVENT.modifiers & cmdKey) != 0) {
- FlushEvents(keyDown | autoKey, 0);
- gQuitNow = TRUE;
- }
- else if ((EVENT.modifiers & cmdKey) != 0) {
- if (EVENT.what == keyDown) {
- menuChoice = MenuKey(EVENT.message & charCodeMask);
- if (HiWord(menuChoice) != 0
- && (browserPtr = IsOurWindow(theWindow)) != NULL)
- DoCommand(browserPtr, menuChoice);
- else if ((browserPtr = IsOurWindow(theWindow)) != NULL)
- DoWindowKeyDown(browserPtr);
- else {
- SysBeep(10);
- }
- }
- }
- else if ((browserPtr = IsOurWindow(theWindow)) != NULL)
- DoWindowKeyDown(browserPtr);
- else {
- SysBeep(10);
- }
- break;
- case mouseDown:
- DoMouseEvent();
- break;
- case updateEvt:
- theWindow = (WindowPtr) EVENT.message;
- GetPort(&savePort);
- SetPort(theWindow);
- BeginUpdate(theWindow);
- EraseRect(&theWindow->portRect);
- if ((browserPtr = IsOurWindow(theWindow)) != NULL) {
- UpdateControls(theWindow, theWindow->visRgn);
- MyDrawGrowIcon(theWindow);
- AOMUpdatePanel(BROWSER.aomPtr, theWindow->visRgn);
- UpdateLog(RESULT_LOG);
- UpdateLog(ERROR_LOG);
- }
- EndUpdate(theWindow);
- SetPort(savePort);
- break;
- case activateEvt:
- theWindow = (WindowPtr) EVENT.message;
- isActivating = ((EVENT.modifiers & activeFlag) != 0);
- goto activateEvent;
- break;
- case osEvt:
- switch (((unsigned long) EVENT.message) >> 24) {
- case mouseMovedMessage:
- break;
- case suspendResumeMessage:
- isActivating = ((EVENT.message & 0x01) != 0);
- activateEvent: if (isActivating) {
- /*
- * Activate this window. Activate events
- * define theWindow from the event record,
- * while suspend/resume uses the pre-set
- * FrontWindow value.
- */
- SelectWindow(theWindow);
- (void) TEFromScrap();
- }
- if ((browserPtr = IsOurWindow(theWindow)) != NULL) {
- ActivateLog(ERROR_LOG, isActivating);
- ActivateLog(RESULT_LOG, isActivating);
- /*
- * Globalize it so we can find the current
- * window in the debugger.
- */
- if (isActivating) {
- gCurrentBrowser = browserPtr;
- gCurrentLog = ERROR_LOG;
- }
- MyDrawGrowIcon(theWindow);
- }
- else {
- /* Desk accessory or what? */
- }
- gInForeground = isActivating;
- gUpdateMenusNeeded = TRUE;
- break;
- }
- break;
- }
- }
- theWindow = FrontWindow(); /* Can be changed by events */
- if (IsOurWindow(theWindow)) {
- SetPort(theWindow);
- //** BalloonHelp(theWindow);
- }
- }
-
- /*
- * DoMouseEvent
- * The user clicked on something. Handle application-wide
- * processing here, or call a Directory Browser function
- * for specific action.
- */
- void
- DoMouseEvent(void)
- {
- register BrowserPtr browserPtr;
- WindowPtr theWindow;
- short whichPart;
- short minimumWidth;
- short minimumHeight;
-
- whichPart = FindWindow(EVENT.where, &theWindow);
- if (theWindow == NULL)
- theWindow = FrontWindow();
- if (whichPart == inMenuBar
- && (browserPtr = IsOurWindow(theWindow)) == NULL)
- theWindow = FrontWindow();
- browserPtr = IsOurWindow(theWindow);
- if (browserPtr != NULL)
- SetPort(theWindow);
- switch (whichPart) {
- case inDesk:
- break;
- case inMenuBar:
- InitCursor();
- if (browserPtr != NULL)
- DoCommand(browserPtr, MenuSelect(EVENT.where));
- break;
- case inDrag:
- DragWindow(theWindow, EVENT.where, &qd.screenBits.bounds);
- break;
- case inGoAway:
- if (TrackGoAway(theWindow, EVENT.where)) {
- if (browserPtr != NULL) {
- DisposeAddressOMatic(browserPtr);
- if (gOpenWindowCount <= 0)
- gQuitNow = TRUE;
- }
- else {
- SysBeep(10);
- }
- }
- break;
- case inZoomIn:
- case inZoomOut:
- if (TrackBox(theWindow, EVENT.where, whichPart)) {
- DoZoomWindow(theWindow, whichPart);
- goto resizeWindow;
- }
- break;
- case inGrow:
- AOMGetDimensions(&minimumWidth, &minimumHeight);
- minimumWidth += kPrivateWidth;
- minimumHeight += kPrivateHeight;
- if (DoGrowWindow(theWindow, minimumWidth, minimumHeight)) {
- resizeWindow: DecorateWindow(browserPtr);
- }
- break;
- case inContent:
- if (theWindow != FrontWindow()) {
- SelectWindow(theWindow);
- if ((browserPtr = IsOurWindow(theWindow)) != NULL) {
- gCurrentBrowser = browserPtr;
- gCurrentLog = ERROR_LOG;
- }
- }
- else if ((browserPtr = IsOurWindow(theWindow)) != NULL) {
- DoContentClick(browserPtr);
- }
- else {
- /* Nothing happens here */
- }
- break;
- default:
- break; /* Might be for the SDP Panel */
- }
- }
-
- /*
- * DoCommand
- * Process a menu or keystroke command.
- */
- void
- DoCommand(
- register BrowserPtr browserPtr,
- long menuChoice
- )
- {
- short menuItem;
- Str255 menuText;
- GrafPtr savePort;
-
- menuItem = LoWord(menuChoice);
- switch (HiWord(menuChoice)) {
- case MENU_Apple:
- if (menuItem == kAppleAbout)
- ;
- else {
- GetItem(gAppleMenu, menuItem, menuText);
- AdjustEditMenu(TRUE);
- GetPort(&savePort);
- OpenDeskAcc(menuText);
- SetPort(savePort);
- AdjustEditMenu(browserPtr == NULL);
- }
- break;
- case MENU_File:
- switch (menuItem) {
- case kFileCreateWindow:
- MakeAddressOMaticWindow();
- break;
- case kFileCloseWindow:
- if (browserPtr != NULL) {
- DisposeAddressOMatic(browserPtr);
- if (gOpenWindowCount <= 0)
- gQuitNow = TRUE;
- }
- break;
- case kFileSetIdentity:
- if (browserPtr != NULL && gHasAOCEToolbox)
- SetSpecificIdentity(browserPtr);
- break;
- case kFileQuit:
- gQuitNow = TRUE;
- break;
- }
- break;
- case MENU_Edit:
- if (SystemEdit(menuItem - 1) == FALSE)
- SysBeep(10);
- break;
- }
- HiliteMenu(0);
- }
-
- /*
- * AdjustMenus
- * Enable/disable menu options.
- */
- void
- AdjustMenus(void)
- {
- register BrowserPtr browserPtr;
-
- browserPtr = IsOurWindow(FrontWindow());
- EnableItem(gFileMenu, kFileQuit);
- EnableItem(gFileMenu, kFileCreateWindow);
- if (browserPtr != NULL) {
- EnableItem(gFileMenu, kFileCloseWindow);
- if (gHasAOCEToolbox)
- EnableItem(gFileMenu, kFileSetIdentity);
- }
- else {
- DisableItem(gFileMenu, kFileCloseWindow);
- DisableItem(gFileMenu, kFileSetIdentity);
- }
- AdjustEditMenu(browserPtr == NULL);
- gUpdateMenusNeeded = FALSE;
- }
-
- /*
- * AdjustEditMenu
- * Enable/disable Edit Menu options.
- */
- void
- AdjustEditMenu(
- Boolean isDeskAcc
- )
- {
- if (isDeskAcc) {
- EnableItem(gEditMenu, kEditUndo);
- EnableItem(gEditMenu, kEditCut);
- EnableItem(gEditMenu, kEditCopy);
- EnableItem(gEditMenu, kEditPaste);
- EnableItem(gEditMenu, kEditClear);
- }
- else {
- DisableItem(gEditMenu, kEditUndo);
- DisableItem(gEditMenu, kEditCut);
- DisableItem(gEditMenu, kEditCopy);
- DisableItem(gEditMenu, kEditPaste);
- DisableItem(gEditMenu, kEditClear);
- }
- }
-
- /*
- * DeleteAllWindows
- * This is called when the application quits to make
- * sure that all windows are deleted. It isn't really
- * needed until we have to handle open files.
- */
- void
- DeleteAllWindows(void)
- {
- WindowPtr thisWindow;
- WindowPeek nextWindow;
- register BrowserPtr browserPtr;
-
- thisWindow = FrontWindow();
- while (thisWindow != NULL) {
- nextWindow = ((WindowPeek) thisWindow)->nextWindow;
- if ((browserPtr = IsOurWindow(thisWindow)) != NULL)
- DisposeAddressOMatic(browserPtr);
- thisWindow = (WindowPtr) nextWindow;
- }
- }
-
- /*
- * ClearMemory
- * This is a utility function that clears a block
- * of memory. It isn't very efficient. It us
- * normally called by executing the CLEAR macro
- * which expands CLEAR(thing) to
- * ClearMemory(&thing, sizeof thing);
- */
- void
- ClearMemory(
- void *recordPtr,
- register Size recordSize
- )
- {
- register char *rp;
-
- rp = (char *) recordPtr;
- while (recordSize > 0) {
- *rp++ = 0;
- --recordSize;
- }
- }
-
- /*
- * InitMacintosh
- * Perform the normal application initialization.
- * This should probably be extended to add a
- * "rainy day" memory fund. The only thing
- * this module does is initialize the managers.
- */
- void
- InitMacintosh(void)
- {
- int i;
- long response;
-
- MaxApplZone();
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(NULL);
- HNoPurge((Handle) GetCursor(watchCursor));
- SetCursor(*GetCursor(watchCursor));
- if (Gestalt(gestaltQuickdrawFeatures, &response) == noErr
- && (response & (1 << gestaltHasColor)) != 0)
- gHasColorQuickDraw = TRUE;
- for (i = 0; i < 3; i++)
- EventAvail(everyEvent, &EVENT);
- }
-
- /*
- * InitApplication
- * Continue initialization. Failure dies a horrible death.
- */
- void
- InitApplication(void)
- {
- Handle menuBarHdl;
-
- (void) TEFromScrap();
- menuBarHdl = GetNewMBar(MBAR_MenuBar);
- SetMenuBar(menuBarHdl);
- gAppleMenu = GetMHandle(MENU_Apple);
- gFileMenu = GetMHandle(MENU_File);
- gEditMenu = GetMHandle(MENU_Edit);
- AddResMenu(GetMHandle(MENU_Apple), 'DRVR');
- DrawMenuBar();
- }
-
- /*
- * IsOurWindow
- * Return BrowserPtr if this is a directory browser window.
- */
- BrowserPtr
- IsOurWindow(
- WindowPtr theWindow
- )
- {
- if (theWindow == NULL
- || ((WindowPeek) theWindow)->windowKind != userKind)
- return (NULL);
- else {
- return ((BrowserPtr) theWindow);
- }
- }
-
- /*
- *** AddressOMatic stuff
- */
-
- /*
- * SetupTypesList creates a list of "addressable" objects.
- */
- void
- SetupTypesList(void)
- {
- OSErr status;
- RString addressCategory;
- PackedRStringListHandle categoryTypes;
-
- OCECToRString(
- kDETCategoryAddressItems,
- smRoman,
- &addressCategory,
- kRStringMaxBytes
- );
- status = SDPGetCategoryTypes(&addressCategory, &categoryTypes);
- /*
- * Get a private copy of the category types so we can lock
- * it down in memory without concern that someone will unlock it.
- */
- if (status == noErr)
- status = HandToHand((Handle *) &categoryTypes);
- if (status == noErr) {
- MoveHHi((Handle) categoryTypes);
- HLock((Handle) categoryTypes);
- gTypeCount = OCEUnpackPathName(*categoryTypes, gTypeList, kMaxPathParts);
- }
- if (status != noErr)
- ErrorAlert(ALRT_NonFatal, status, "\pSetupTypesList");
- }
-
- void
- MakeAddressOMaticWindow(void)
- {
- OSErr status;
- Rect boundsRect;
- WindowPtr theWindow;
- short minimumWidth;
- short minimumHeight;
- BrowserPtr browserPtr;
- long response;
- Boolean hasColorQuickDraw;
-
-
- SetCursor(*GetCursor(watchCursor));
- hasColorQuickDraw = FALSE;
- if (Gestalt(gestaltQuickdrawVersion, &response) == noErr
- && response >= gestalt8BitQD)
- hasColorQuickDraw = TRUE;
- browserPtr = (BrowserPtr) NewPtrClear(sizeof (BrowserRecord));
- if (browserPtr == NULL) {
- ErrorAlert(ALRT_Continue, MemError(), "\pCreate browser record");
- return;
- }
- theWindow = NULL;
- /*
- * Ignore errors from GetUserIdentity for testing.
- */
- (void) GetUserIdentity(&BROWSER.userIdentity);
- AOMGetDimensions(&minimumWidth, &minimumHeight);
- boundsRect = qd.screenBits.bounds;
- InsetRect(&boundsRect, 4, 4);
- boundsRect.top += (GetMBarHeight() * 2);
- boundsRect.bottom = boundsRect.top + minimumHeight + kPrivateHeight;
- boundsRect.right = boundsRect.left + minimumWidth + kPrivateWidth;
- OffsetRect(&boundsRect, gWindowOffset, gWindowOffset);
- gWindowOffset += 16;
- if (hasColorQuickDraw) {
- theWindow = NewCWindow(
- &WINDOW, /* Use our storage */
- &boundsRect, /* Initial bounds */
- "\pAddressOMatic™ Test", /* Title */
- TRUE, /* Make visible */
- zoomDocProc, /* Normal document */
- (WindowPtr) -1L, /* In front */
- TRUE, /* Has GoAway box */
- 0 /* No refCon yet */
- );
- }
- else {
- theWindow = NewWindow(
- &WINDOW, /* Use our storage */
- &boundsRect, /* Initial bounds */
- "\pAddressOMatic™ Test", /* Title */
- TRUE, /* Make visible */
- zoomDocProc, /* Normal document */
- (WindowPtr) -1L, /* In front */
- TRUE, /* Has GoAway box */
- 0 /* No refCon yet */
- );
- }
- if (theWindow != (WindowPtr) &WINDOW) {
- ErrorAlert(ALRT_Continue, MemError(), "\pCreate browser window");
- return;
- }
- SetPort((GrafPtr) &WINDOW);
- DecorateWindow(browserPtr);
- ValidRect(&WINDOW.port.portRect);
- ERROR_LOG = CreateLog(&BROWSER.logRect, geneva, 9, 0);
- gCurrentLog = ERROR_LOG;
- status = noErr;
- if (ERROR_LOG == NULL) {
- status = MemError();
- ErrorAlert(ALRT_Continue, status, "\pCreate error log");
- }
- RESULT_LOG = CreateLog(&BROWSER.destRect, geneva, 9, 0);
- if (RESULT_LOG == NULL) {
- status = MemError();
- ErrorAlert(ALRT_Continue, status, "\pCreate recipient log");
- }
- if (status == noErr) {
- /*
- * Draw the logs when we start as AOMNewPanel takes a while
- */
- UpdateLog(ERROR_LOG);
- UpdateLog(RESULT_LOG);
- SetCursor(*GetCursor(watchCursor));
- status = AOMNewPanel(
- &PANEL, /* Result */
- theWindow, /* In this window */
- &BROWSER.panelRect, /* In this panel */
- TRUE, /* Initially visible */
- TRUE, /* Initially enabled */
- BROWSER.userIdentity, /* Current identity */
- #if USE_MAIL_ADDRESSES
- gTypeList, /* Addressable types */
- gTypeCount, /* Zero type count implies all */
- #else
- NULL, /* All types */
- 0, /* Zero type count */
- #endif
- 0, /* No refCon */
- ( kAOMAllActionButtons /* All action buttons */
- | kAOMStandardRadioButtons /* And normal radio buttons */
- | kAOMAllRadioButtons /* All radio buttons */
- ),
- kAOMEnablePanelBit, /* Initial radio button mode */
- STRN_AOMLabels, /* Item labels */
- STRN_BrowsePanelHelpStrings, /* Browser help STR# resource */
- STRN_PDPanelHelpStrings, /* Personal catalog help string */
- STRN_FindPanelHelpStrings, /* Find Panel help strings */
- NULL, /* Initial RLI (none) */
- #if USE_MAIL_ADDRESSES
- ( kEnumDistinguishedNameMask /* Enumeration choices */
- | kEnumAliasMask
- | kEnumDNodeMask
- ),
- kExactMatch, /* DirMatchWith */
- #else
- kEnumAllMask, /* All possible enumerations */
- kMatchAll, /* All matches */
- #endif
- 1 /* Simultaneous search count */
- #ifdef ENABLE_TYPEIN
- ,
- OCEGetIndRecordType(kUserRecTypeNum) /* Type-in record ID */
- #endif
- );
- }
- #if 0
- if (hasColorQuickDraw) /* Debug only. */
- DumpAuxColorRecord(browserPtr);
- #endif
- InitCursor();
- if (status == noErr) {
- ShowWindow(theWindow);
- SelectWindow(theWindow);
- gCurrentBrowser = browserPtr;
- ActivateLog(ERROR_LOG, TRUE);
- ActivateLog(RESULT_LOG, TRUE);
- ++gOpenWindowCount;
- }
- else {
- ErrorAlert(ALRT_Continue, status, "\pCreating AOM Panel");
- gCurrentLog = NULL;
- if (theWindow != NULL) {
- if (PANEL != NULL)
- AOMDisposePanel(PANEL);
- DisposeLog(RESULT_LOG);
- DisposeLog(ERROR_LOG);
- CloseWindow((WindowPtr) &WINDOW);
- }
- if (browserPtr != NULL)
- DisposePtr((Ptr) browserPtr);
- }
- InitCursor();
- }
-
- void
- DecorateWindow(
- register BrowserPtr browserPtr
- )
- {
- InvalRect(&WINDOW.port.portRect);
- BROWSER.panelRect = WINDOW.port.portRect;
- BROWSER.panelRect.top += kSlop;
- BROWSER.panelRect.left += kScrollBarWidth;
- BROWSER.panelRect.right -= kScrollBarWidth;
- BROWSER.panelRect.bottom -= kPrivateHeight;
- BROWSER.destRect = WINDOW.port.portRect;
- BROWSER.destRect.top = BROWSER.panelRect.bottom + kSlop;
- BROWSER.destRect.bottom = BROWSER.destRect.top + kDestinationHeight;
- BROWSER.destRect.right += 1;
- BROWSER.logRect = WINDOW.port.portRect;
- BROWSER.logRect.top = BROWSER.destRect.bottom + kSlop;
- BROWSER.logRect.bottom = WINDOW.port.portRect.bottom - kScrollBarWidth + 1;
- BROWSER.logRect.right += 1;
- if (PANEL != NULL)
- (void) AOMAdjustPanel(PANEL, &BROWSER.panelRect);
- if (ERROR_LOG != NULL) {
- MoveLog(
- ERROR_LOG,
- BROWSER.logRect.left,
- BROWSER.logRect.top
- );
- SizeLog(
- ERROR_LOG,
- width(BROWSER.logRect),
- height(BROWSER.logRect)
- );
- }
- if (RESULT_LOG != NULL) {
- MoveLog(
- RESULT_LOG,
- BROWSER.destRect.left,
- BROWSER.destRect.top
- );
- SizeLog(
- RESULT_LOG,
- width(BROWSER.destRect),
- height(BROWSER.destRect)
- );
- }
- }
-
- void
- SetSpecificIdentity(
- BrowserPtr browserPtr
- )
- {
- OSErr status;
- AuthIdentity userIdentity;
- SDPIdentityKind selectedKind;
-
- status = SDPPromptForID(
- &userIdentity, /* AuthIdentity *id */
- NULL, /* Default guest prompt */
- NULL, /* Default specific prompt */
- NULL, /* Default local prompt */
- NULL, /* RString *recordType */
- ( /* SDPIdentityKind permittedKinds */
- kSDPLocalIdentityMask /* Local identity */
- | kSDPSpecificIdentityMask /* or specific identity */
- | kSDPGuestMask /* or guest identity */
- ),
- &selectedKind, /* SDPIdentityKind *selectedKind */
- NULL, /* RecordID *loginFilter */
- 0 /* SDPLoginFilterKind filterKind */
- );
- if (status == noErr) {
- status = AOMSetIdentity(BROWSER.aomPtr, userIdentity);
- }
- }
-
- void
- DisposeAddressOMatic(
- BrowserPtr browserPtr
- )
- {
- (void) AOMDisposePanel(BROWSER.aomPtr);
- DisposeLog(RESULT_LOG);
- DisposeLog(ERROR_LOG);
- CloseWindow((WindowPtr) &WINDOW);
- DisposePtr((Ptr) browserPtr);
- --gOpenWindowCount;
- if (gOpenWindowCount <= 0)
- gQuitNow = TRUE;
- }
-
- /*
- * We don't have any content click actions.
- */
- void
- DoContentClick(
- BrowserPtr browserPtr
- )
- {
- DoClickInLog(ERROR_LOG, &EVENT);
- DoClickInLog(RESULT_LOG, &EVENT);
- }
-
- /*
- * We don't have any content key down actions -- except that we should
- * handle tabbing in/out of the panel.
- */
- void
- DoWindowKeyDown(
- BrowserPtr browserPtr
- )
- {
- #pragma unused (browserPtr)
- }
-
- /*
- * Call the AOM Panel and return TRUE if we must handle the event..
- */
- Boolean
- DoPanelEvent(
- BrowserPtr browserPtr
- )
- {
- OSErr status;
- Boolean result;
- #define AOM (*BROWSER.aomPtr)
-
- result = TRUE;
- if (BROWSER.aomPtr != NULL) {
- status = AOMPanelEvent(BROWSER.aomPtr, &EVENT, &BROWSER.whatHappened);
- if (status == noErr) {
- DisplayEventString(browserPtr);
- result = ((BROWSER.whatHappened & kAOMAppMustHandleEventMask) != 0);
- /* TBS: handle button hits */
- if ((BROWSER.whatHappened & kAOMSelectedAnItemMask) != 0) {
- DisplayLogString(ERROR_LOG, "\pMain: selected");
- }
- if ((BROWSER.whatHappened & kAOMChangedSelectionMask) != 0) {
- DisplayLogString(ERROR_LOG, "\pMain: changed");
- }
- if ((BROWSER.whatHappened & kAOMAnyActionButtonHitMask) != 0) {
- DisplayLogString(ERROR_LOG, "\pMain: button");
- ProcessAOMSelection(browserPtr);
- }
- /*
- * This copies the state of the Find "searching" flag
- * to the window title. It is interesting only for debugging.
- */
- gFindInProgress =
- (BROWSER.whatHappened & kAOMFindInProgressMask) != 0;
- if (gFindInProgress != BROWSER.wasFinding) {
- BROWSER.wasFinding = gFindInProgress;
- SetWTitle(
- (WindowPtr) &WINDOW,
- (gFindInProgress)
- ? "\pSearch Started"
- : "\pSearch Stopped"
- );
- }
- }
- }
- return (result);
- }
-
- void
- ProcessAOMSelection(
- register BrowserPtr browserPtr
- )
- {
- OSErr status;
-
- if (BROWSER.selection != NULL) {
- /*
- * TBS: this is incorrect. We must dispose
- * of the recipient list
- */
- DisposePtr((Ptr) BROWSER.selection);
- }
- BROWSER.selection = NULL;
- BROWSER.selectionSize = 0;
- BROWSER.recipientList = NULL;
- status = AOMExtractSelection(
- BROWSER.aomPtr,
- &BROWSER.selectionSize,
- &BROWSER.selection
- );
- LogStatus(ERROR_LOG, status, "\pAOMExtractSelection");
- if (status == noErr) {
- #if USE_MAIL_ADDRESSES
- status = SMPResolveToRecipient(
- BROWSER.selection,
- &BROWSER.recipientList,
- BROWSER.userIdentity
- );
- LogStatus(ERROR_LOG, status, "\pSMPResolveToRecipient");
- if (status == noErr)
- DisplayRecipients(browserPtr);
- else {
- NOTE("\p• SMPResolveToRecipient failed, DSSpec:");
- DisplayOneDSSpec(browserPtr, BROWSER.selection);
- }
- #else
- NOTE("\p• DSSpec");
- DisplayOneDSSpec(browserPtr, BROWSER.selection);
- #endif
- }
- }
-
- /*
- * Extract the recipients from BROWSER.recipientList and display
- * them in the error log area.
- */
- void
- DisplayRecipients(
- register BrowserPtr browserPtr
- )
- {
- SMPRecipientDescriptorPtr recipPtr;
- #define RECIP (*recipPtr)
-
- DisplayLogString(RESULT_LOG, "\p•");
- for (recipPtr = BROWSER.recipientList;
- recipPtr != NULL;
- recipPtr = RECIP.next) {
- /*
- * Extract the record name from RECIP.theAddress. This is of type
- * MailRecipient which is, ultimately, of type DSSpec. So, to
- * summarize: the DSSpec contains an entity specifier which is
- * a pointer to a LocalRecordID. The actual recipient's name
- * is in the local record name field.
- */
- LOG_RString(
- "\p• Name",
- RECIP.theAddress.entitySpecifier->local.recordName
- );
- LOG_RString(
- "\p• Type",
- RECIP.theAddress.entitySpecifier->local.recordType
- );
- DisplayOneDSSpec(browserPtr, (PackedDSSpecPtr) RECIP.recipient);
- }
- }
-
- void
- DisplayOneDSSpec(
- register BrowserPtr browserPtr,
- PackedDSSpecPtr theDSSpecPtr
- )
- {
- DSSpecDumpRecord theDSSpecDumpRecord;
-
- UnpackPackedDSSpec(browserPtr,theDSSpecPtr, &theDSSpecDumpRecord);
- DisplayUnpackedDSSpec(browserPtr, &theDSSpecDumpRecord);
- DisposeDSSpecDumpRecord(browserPtr, &theDSSpecDumpRecord);
-
- }
-
- void
- DisplayEventString(
- register BrowserPtr browserPtr
- )
- {
- register EventStringPtr ep;
- static Boolean wasFinding;
- Boolean isFinding;
-
- for (ep = (EventStringPtr) gEventString; ep->stateBit != 0; ep++) {
- if ((ep->stateBit & BROWSER.whatHappened) != 0)
- DisplayLogString(ERROR_LOG, ep->message);
- }
- isFinding = (BROWSER.whatHappened & kAOMFindInProgressMask) != 0;
- if (wasFinding != isFinding) {
- DisplayLogString(
- ERROR_LOG,
- (isFinding)
- ? "\pFinding started"
- : "\pFinding stopped"
- );
- wasFinding = isFinding;
- }
- }
-
- /*
- * Get the user's local identity. On success, the identity is
- * stored in the specified location. The only expected error
- * is userCanceledErr, which probably means "just exit the
- * application." Other errors should be displayed:
- * Return noErr Installed and available.
- * Return userCanceledErr User canceled identity prompt
- * Return kOCEToolboxNotOpen Installed, but not available,
- * Return gestaltUndefSelectorErr Not present on this machine
- */
- OSErr
- GetUserIdentity(
- AuthIdentity *userIdentity
- )
- {
- long gestaltResponse;
- SDPIdentityKind selectedKind;
- AuthParamBlock authParamBlock;
- OSErr status;
-
- /*
- * Make sure this Macintosh supports AOCE.
- */
- status = Gestalt(gestaltOCEToolboxAttr, &gestaltResponse);
- if (status == noErr
- && (gestaltResponse & gestaltOCETBAvailable) == 0)
- status = kOCEToolboxNotOpen;
- if (status == noErr) {
- /*
- * OCE Setup: get the user's local authentication identity. If it's
- * already set, we can do this silently. If it's not set (the system
- * has just been started), we'll prompt for the user's identity
- * and password.
- *
- * The only expected error is "Cancel" from SDPPromptForIdentity.
- */
- status = AuthGetLocalIdentity(
- &authParamBlock, /* Parameter block */
- FALSE /* Synchronous */
- );
- }
- if (status == noErr) {
- /*
- * The user identity has already been specified.
- */
- *userIdentity = authParamBlock.getLocalIdentityPB.theLocalIdentity;
- }
- else if (status == kOCELocalAuthenticationFail) {
- /*
- * No user identity has been specified. Ask for the user to specify
- * the local identity.
- */
- status = SDPPromptForID(
- userIdentity, /* AuthIdentity *id */
- NULL, /* Default guest prompt */
- NULL, /* Default specific prompt */
- NULL, /* Default local prompt */
- NULL, /* RString *recordType */
- ( /* SDPIdentityKind permittedKinds */
- kSDPLocalIdentityMask /* Local identity */
- | kSDPSpecificIdentityMask /* or specific identity */
- | kSDPGuestMask /* or guest identity */
- ),
- &selectedKind, /* SDPIdentityKind *selectedKind */
- NULL, /* RecordID *loginFilter */
- 0 /* SDPLoginFilterKind filterKind */
- );
- }
- else {
- /* AuthGetLocalIdentity is very unhappy. */
- }
- return (status);
- }
-
- /*
- * Make sure this Macintosh supports AOCE.
- */
- void
- CheckForAOCEToolbox(void)
- {
- OSErr status;
- long gestaltResponse;
-
- status = Gestalt(gestaltOCEToolboxAttr, &gestaltResponse);
- if (status == noErr
- && (gestaltResponse & gestaltOCETBAvailable) == 0)
- status = kOCEToolboxNotOpen;
- gHasAOCEToolbox = (status == noErr);
- }
-
-
- /*
- * Debug: write the AuxColorRecord table to the error log.
- */
- void
- DumpAuxColorRecord(
- register BrowserPtr browserPtr
- )
- {
- AuxWinHandle auxWinHandle;
- CTabHandle ctabHandle;
- AuxCtlHandle acHandle;
- CCTabHandle cctabHandle;
-
- short i;
- Str255 work;
- Str255 value;
- RGBColor saveForeColor;
- RGBColor saveBackColor;
- RGBColor foreColor;
- RGBColor backColor;
- #define CTAB (**ctabHandle)
- #define CTABLE (CTAB.ctTable)
-
- (void) GetAuxWin((WindowPtr) &WINDOW, &auxWinHandle);
- if (auxWinHandle != NULL) {
- DisplayLogString(ERROR_LOG, "\p• Window Color Table");
- ctabHandle = (**auxWinHandle).awCTable;
- for (i = 0; i <= CTAB.ctSize; i++) {
- NumToString(i, work);
- pstrcat(work, "\p = ");
- NumToString(CTABLE[i].value, value);
- pstrcat(work, value);
- pstrcat(work, "\p ");
- DumpColor(&CTABLE[i].rgb, work);
- DisplayLogString(ERROR_LOG, work);
- }
- }
- #undef CTAB
- #undef CTABLE
- #define CTAB (**cctabHandle)
- #define CTABLE (CTAB.ctTable)
- (void) GetAuxCtl(NULL, &acHandle);
- if (acHandle != NULL) {
- DisplayLogString(ERROR_LOG, "\p• Default Control Color");
- cctabHandle = (**acHandle).acCTable;
- for (i = 0; i <= CTAB.ctSize; i++) {
- NumToString(i, work);
- pstrcat(work, "\p = ");
- NumToString(CTABLE[i].value, value);
- pstrcat(work, value);
- pstrcat(work, "\p ");
- DumpColor(&CTABLE[i].rgb, work);
- DisplayLogString(ERROR_LOG, work);
- }
- }
- #undef CTAB
- #undef CTABLE
- GetForeColor(&saveForeColor);
- GetBackColor(&saveBackColor);
- PenNormal();
- foreColor.red = foreColor.green = foreColor.blue = 0; /* Black */
- backColor.red = backColor.green = backColor.blue = 65535; /* White */
- DisplayLogString(ERROR_LOG, "\p• Gray -> White");
- while (GetGray(GetGDevice(), &backColor, &foreColor)) {
- work[0] = 0;
- DumpColor(&foreColor, work);
- DisplayLogString(ERROR_LOG, work);
- }
- foreColor.red = foreColor.green = foreColor.blue = 65535; /* White */
- backColor.red = backColor.green = backColor.blue = 0; /* Black */
- DisplayLogString(ERROR_LOG, "\p• Gray -> Black");
- while (GetGray(GetGDevice(), &backColor, &foreColor)) {
- work[0] = 0;
- DumpColor(&foreColor, work);
- DisplayLogString(ERROR_LOG, work);
- }
- RGBForeColor(&saveForeColor);
- RGBBackColor(&saveBackColor);
- }
-
- void
- DumpColor(
- RGBColor *theColor,
- StringPtr result
- )
- {
- Str255 value;
-
- pstrcat(result, "\p[");
- NumToString(theColor->red, value);
- pstrcat(result, value);
- pstrcat(result, "\p, ");
- NumToString(theColor->green, value);
- pstrcat(result, value);
- pstrcat(result, "\p, ");
- NumToString(theColor->blue, value);
- pstrcat(result, value);
- pstrcat(result, "\p]");
- }
-